#ifndef BUFFER_H
#define BUFFER_H

#include <cstddef>

// Buffer I/O of Compiler (Scanner)
class Buffer {
private:
	char* inputBuffer;
	char* outputBuffer;

	int inputfile;
	int outputfile;
	int readfile;
	int writefile;

	unsigned int inputindex;
	unsigned int outputindex;
	unsigned int fileindex;

	bool buffer1IsAlreadyChanged;
	bool buffer2IsAlreadyChanged;
	bool isFinished;
	bool isInitialized;

	bool initInput();
	bool initOutput();

	bool reloadBuffer(int position);
	void flush();

public:
	Buffer();
	~Buffer();

	// initializes the Buffer with input- and output file
	bool init(const char* inputfile, const char* outputfile);

	// return next character from Buffer
	char getChar();
	// goes one step back in Buffer (decrement index)
	int ungetChar(const size_t n);

	// copies the last characters from buffer to given position (lexem storage)
	int copyString(const size_t lastChars, char* position);
	// puts the given string into output buffer
	// writes output buffer into specified output file
	void writeString(const char* printString);

};

#endif
